# encoding: utf-8
# 项目名称： drf-simple
# @File  : view.py
# @Author: SunHao
# @Desc :  继承 APIVIEW
# @Date  :   16:41 2025/03/16
from rest_framework.views import APIView


class ExtendView(APIView):
    def check_permissions(self, request):
        """
            这个是对drf源码的扩展
            当 MyPermission1，MyPermission2，MyPermission3
            只要满足其中1个条件，就通过了，但是当全部条件都不满足时，
            就返回默认第1个不满足条件的提示信息
        """
        no_permission_objects = self.get_permissions()
        for permission in self.get_permissions():
            if permission.has_permission(request, self):
                return
            else:
                no_permission_objects.append(permission)
        else:
            self.permission_denied(
                request,
                message=getattr(no_permission_objects[0], "message", None),
                code=getattr(no_permission_objects[0], "code", None)
            )
